package com.jic.order.impl;

import com.jic.common.base.vo.Page;
import com.jic.order.base.BaseService;
import com.jic.order.entity.OrderDeliveryType;
import com.jic.order.mapper.OrderDeliveryTypeMapper;
import com.jic.order.request.OrderDeliveryTypeRequest;
import com.jic.order.response.OrderDeliveryTypeResponse;
import com.jic.common.base.vo.PageResult;
import com.jic.order.service.OrderDeliveryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单配送方式
 * @author : 
 * @email : 
 * @since : 2020-01-16 07:57:33
 * @version : v1.0.0
 */
@Service
public class OrderDeliveryTypeServiceImpl extends BaseService implements OrderDeliveryTypeService {

    @Autowired
    private OrderDeliveryTypeMapper orderDeliveryTypeMapper;

    @Override
    public long insert(OrderDeliveryTypeRequest orderDeliveryType) {
        long flag = orderDeliveryTypeMapper.insert(orderDeliveryType);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return orderDeliveryTypeMapper.delete(id);
    }

    @Override
    public long update(OrderDeliveryTypeRequest orderDeliveryType) {

        return orderDeliveryTypeMapper.update(orderDeliveryType);
    }

    @Override
    public OrderDeliveryType queryByPrimaryKey(Long id) {
        return orderDeliveryTypeMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<OrderDeliveryType> query(OrderDeliveryType orderDeliveryType) {
        return orderDeliveryTypeMapper.query(orderDeliveryType);
    }

    @Override
    public PageResult<OrderDeliveryTypeResponse> queryPage(OrderDeliveryTypeRequest orderDeliveryType, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<OrderDeliveryTypeResponse> list = orderDeliveryTypeMapper.queryPage(startIndex, pageQuery.getLimit(), orderDeliveryType);
        long count = orderDeliveryTypeMapper.queryPageCount(orderDeliveryType);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }


}